using System;
using System.Threading.Tasks;
using JlPay.Sdk.Core;
using JlPay.Sdk.Services.Ledger.Bill;
using JlPay.Sdk.Models.Ledger.Bill;

namespace JlPay.Sdk.Examples.Ledger.Bill
{
    /// <summary>
    /// 账单申请URL示例
    /// </summary>
    public class BillApplyUrlExample
    {
        /// <summary>
        /// 创建配置对象
        /// </summary>
        /// <returns>配置对象</returns>
        private static Config CreateConfig()
        {
            return DemoConfig.CreateConfigWithCrypto();
        }

        /// <summary>
        /// 构建账单申请URL请求
        /// </summary>
        /// <returns>请求对象</returns>
        private static BillApplyUrlRequest BuildBillApplyUrlRequest()
        {
            var request = new BillApplyUrlRequest();
            
            // 设置请求参数
            request.OrgCode = "50720711";
            request.BillDate = "2024-08-15";
            
            return request;
        }

        /// <summary>
        /// 账单申请URL示例
        /// </summary>
        public static async Task BillApplyUrlDemoAsync()
        {
            Console.WriteLine("开始执行账单申请URL示例");
            
            try
            {
                // 创建配置对象和账单服务
                var config = CreateConfig();
                var billService = new BillService(config);
                
                // 创建账单申请URL请求
                var request = BuildBillApplyUrlRequest();
                
                // 发送请求
                var response = await billService.ApplyBillUrlAsync(request);
                
                // 处理响应结果
                response.HandleResponse("账单申请URL", config);
            }
            catch (Exception ex)
            {
                var config = CreateConfig();
                var response = new BillApplyUrlResponse();
                response.HandleResponseWithException("账单申请URL", config, ex);
            }
            
            Console.WriteLine("账单申请URL示例执行完毕");
        }
    }
} 